<template>
    <!--<div class="mui-numbox" data-numbox-min='1' data-numbox-max='1000' data-numbox-step='10'>-->
    <!--<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>-->
    <!--<input id="test" class="mui-input-numbox" type="number" v-model="boxnum" />-->
    <!--<button class="mui-btn mui-btn-numbox-plus" type="button">+</button>-->
    <!--</div>-->
    <div class="mui-numbox" data-numbox-min='1'>
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input class="mui-input-numbox" type="number" @change="getchange" :value="myvalue" ref="numinput"
               :readonly="readonly"/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min'

    export default {
        mounted() {
            mui('.mui-numbox').numbox().setOption('step', 1)
        },
        data() {
            return {
                myvalue: this.value
            }
        },
        // 获取传过来的值
        props: {
            value: {
                type: Number,
                default: 1
            },
            maxnum: {
                type: Number,
                default: Infinity
            },
            readonly: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            // 当通过异步获取到最大数量的时候手动设置最大数字
            maxnum(newnum) {
                mui('.mui-numbox').numbox().setOption('max', newnum)
            },
            value(data) {
                this.myvalue = data
            }
        }
        ,
        methods: {
            // 当数字变化的时候传数据出去
            getchange() {
                this.$emit('input', parseInt(this.$refs.numinput.value.trim()))
            }
        }
    }
</script>

<style scoped>

</style>